package com.lvyq.myplayer.adapter.ranking

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.lvyq.myplayer.parcelable.SongInfoData
import com.lvyq.myplayer.widget.common.song.SongItemOperationView

/**
 * 文件描述：TheCharItemAdapter
 * 作者：lvyq
 * 创建时间：2025-06-03
 * 修改时间：2025-06-03
 */
class TheCharItemAdapter(var context: Context?,
                         private val itemClickListener: OnItemClickListener):
    RecyclerView.Adapter<TheCharItemAdapter.TheCharItemViewHolder>() {


    var listData=ArrayList<SongInfoData>()

    interface OnItemClickListener {
        fun onItemClick(position: Int, data: SongInfoData,list:ArrayList<SongInfoData>)

        fun onAddItemClick(position: Int, data: SongInfoData)
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TheCharItemViewHolder {
            return TheCharItemViewHolder(SongItemOperationView(parent.context))
    }

    override fun getItemCount(): Int {
        return listData.size
    }

    override fun onBindViewHolder(holder: TheCharItemViewHolder, position: Int) {
        val data = listData[position]
        val item = holder.itemView as SongItemOperationView
        item.setData(data)
        item.setOnClickListener {
            itemClickListener.onItemClick(position, data,listData)
        }
        item.addPlayList.setOnClickListener {
          itemClickListener.onAddItemClick(position, data)
        }

    }
    fun setData(dataList: ArrayList<SongInfoData>) {
        this.listData=dataList
        notifyDataSetChanged()
    }


    inner class TheCharItemViewHolder(view:View): RecyclerView.ViewHolder(view) {

    }

}